package io.modifier.basic.compose.hooks

import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import io.modifier.basic.compose.hooks.data.useState
import kotlin.time.Duration
import kotlinx.coroutines.delay

@Composable
fun <T> useAutoReset(default: T & Any, interval: Duration): MutableState<T & Any> {
    val state = useState(default = default)
    val defaultValue = useCreation { default }
    useEffect(state) {
        delay(interval)
        state.value = defaultValue.current
    }
    return state
}
